Ext.namespace("Milan.commonutils");




//配合windowOnLoad，可以在任何时候获取鼠标的x和y
Milan.commonutils.mouseX = -1;
Milan.commonutils.mouseY = -1;
Milan.commonutils.windowOnLoad = function()
{
	document.body.onmousemove = function(e)
	{
	    e = e || window.event;
	    Milan.commonutils.mouseX = e.pageX || (e.clientX +(document.documentElement.scrollLeft || document.body.scrollLeft));
	    Milan.commonutils.mouseY= e.pageY || (e.clientY +(document.documentElement.scrollTop || document.body.scrollTop));
	    Milan.lastestOperateTime=new Date();
	}
	document.onkeypress=function(e){
		Milan.lastestOperateTime=new Date();
	}
	var animateEff = Milan.commonutils.getCookie("animateEff");
	if (animateEff)
	{
		if (animateEff=="1")
		{
			Milan.commonutils.MODELPOP_ANIMATESHOW = true;
			Milan.commonutils.MODELPOP_ANIMATECLOSE = true;
		}
		else
		{
			Milan.commonutils.MODELPOP_ANIMATESHOW = false;
			Milan.commonutils.MODELPOP_ANIMATECLOSE = false;
		}
	}
	Milan.lastestOperateTime=new Date();
}


/*
* Milan.commonutils.timer
* 定时器
* timer(interval,timeout,interCallBack,overCallBack)
* interval:调用间隔，定时循环调用interCallBack，直到timeout
* timeout:timer生命周期，到时timer结束，并解是overCallBack
* interCallBack和overCallBack(interCount,timePass)
* interCount:循环次数
* timePass:从timer开始逝去的时间
*/
Milan.commonutils.timer = Class.create();
Milan.commonutils.timer.prototype = 
{
	initialize : function(interval,timeout,interCallBack,overCallBack)
	{
		this.interval = interval;
		this.timePass = 0;
		this.interCount = 0;
		this.timeout = timeout;
		this.interCallBack = interCallBack;
		this.overCallBack = overCallBack;
	},
	
	go : function()
	{
		if (this.interCount>0) 
		{
			if (this.interCallBack) this.interCallBack(this.interCount,this.timePass);
			if (this.timePass>=this.timeout)
			{
				if (this.overCallBack) this.overCallBack(this.interCount,this.timePass);
			}
		}
		this.interCount++;
		this.timePass+=this.interval;
		window.setTimeout(this.go,this.interval);		
	}
}

/*
* Milan.commonutils.hashMap
* hashmap(size)
* size:map的size
*
*
*/

Milan.commonutils.hashMap = Class.create();
Milan.commonutils.hashMap.prototype = 
{
	initialize : function(size)
	{
		this.size = size;
		this.keys = new Array(size);
		this.values = new Array(size);
	},
	getKeys : function()
	{
		return this.keys;
	},
	getValues : function()
	{
		return this.values;
	},
	/**
	 * 如果hashmap已经饱和，则删除最先进入
	 * hashmap的键值对然后再push进入新的键值对
	 */
	put : function(key,value)
	{
		if(this.keys.size>=this.size)
		{
			this.keys.splice(0,1);
			this.values.splice(0,1);
		}
		this.keys.push(key);
		this.values.push(value);
	},
	get : function(key)
	{
		var index = this.getKeyIndex(key);
		return this.values[index];
	},
	/**
	 * 返回该由该key索引的值，并删除该key以及其对应的值
	 */
	getNRemove : function(key)
	{
		var index = this.getKeyIndex(key);
		var value = this.values[index];
		this.keys.splice(index,1);
		this.values.splice(index,1);
		return value;
	},
	getSize : function()
	{
		return keys.length;
	},
	/**
	 * 从hashmap中取得最新push进去的一个key的index
	 */
	getKeyIndex : function(key)
	{
		for(var i=this.keys.length-1;i>-1;i--)
		{
			if(keys[i]==key)
				return i;
		}
		return -1;
	},
	/**
	 * 从hashmap中取得最新push进去的一个value的index
	 */
	getValueIndex : function(value)
	{
		for(var i=this.values.length-1;i>-1;i--)
		{
			if(values[i]==value)
				return i;
		}
		return -1;
	}
}



Milan.commonutils.StringBuffer = Class.create();
Milan.commonutils.StringBuffer.prototype = {
	initialize : function(size)
	{
		this._strings=new Array;
	},
	append : function(str)
	{
		this._strings.push(str);
	},
	toString : function()
	{
		return this._strings.join(""); 
	}
}

Ext.namespace("Milan.commonutils.Randomizer");
Milan.commonutils.Randomizer._seed = new Date().getTime();
Milan.commonutils.Randomizer.rnd = function()
{
	Milan.commonutils.Randomizer._seed = (Milan.commonutils.Randomizer._seed*9301+49297) % 233280;	
	return Milan.commonutils.Randomizer._seed/(233280.0);	
}

Milan.commonutils.Randomizer.rand = function(number)
{
	return Math.ceil(Milan.commonutils.Randomizer.rnd()*number);	
}
/**
 * 创建延迟消失的浮现层
 */
Milan.commonutils.createDelayNotifyModel=function(title,message,config){
	if (!config) config = {};
	if(config.escapeHTML===true){
		message = message.replace("<","&lt;");
	}
	config["title"] = title;
	config["message"] = message;
	config["modelType"] = Milan.commonutils.MODELTYPE_DELAYNOTIFY;
	Milan.commonutils.createModelPop(config);
};	
/**
 * 创建一个弹出窗，并将其显示
 * 返回一个弹出窗对象
 * config参数常用属性：
 * url 通过该url去请求数据，并填充到弹出窗口中,源自updateContentUseAjax，如果url参数不设置，则只会创建不会显示。
 * title 弹出窗口标题,源自Milan.widget.Window
 * width 窗口宽度,源自Milan.widget.Window
 * height 弹窗高度,源自Milan.widget.Window
 * onShow 显示出来后的回调,源自Milan.widget.Window
 *
 * 该config参数实际将被传入new Milan.widget.Window和updateContentUseAjax
 * 所以该参数的可用属性是这两个方法的config参数并集.
 */
 /* 这几句是用来打开弹窗渐现的
config["eventX"]=Milan.commonutils.mouseX;	//下面动画选项的必须参数
config["eventY"]=Milan.commonutils.mouseY; //下面动画选项的必须参数
config["animateShow"] =true;		//动画打开
config["animateClose"] =true;		//动画关闭
*/
Milan.commonutils.MODELTYPE_WIDGET	= 0;		//弹窗
Milan.commonutils.MODELTYPE_DIALOG	= 1;		//带一个确定按钮
Milan.commonutils.MODELTYPE_CONFIRM	=	2;		//带确定和取消按钮
Milan.commonutils.MODELTYPE_DELAYNOTIFY = 3;	//延迟消失的浮现层
Milan.commonutils.MODELPOP_ANIMATESHOW = false;	//打开窗口时动画
Milan.commonutils.MODELPOP_ANIMATECLOSE = false;	//关闭窗口时动画

Milan.commonutils.createModelPop = function(config)
{
	/* 这几句是用来打开弹窗渐现的
	config["eventX"]=Milan.commonutils.mouseX;
	config["eventY"]=Milan.commonutils.mouseY;
	config["animateShow"] =true;
	config["animateClose"] =true;*/
	var container;
	if (!config) config = {};
	if (typeof(config["animateShow"])=="undefined")
		config["animateShow"] = Milan.commonutils.MODELPOP_ANIMATESHOW;
	if (typeof(config["animateClose"])=="undefined")
		config["animateClose"] = Milan.commonutils.MODELPOP_ANIMATECLOSE;
	
	switch(config["modelType"])
	{
		case Milan.commonutils.MODELTYPE_DIALOG:
			container= new Milan.widget.Dialog(config["title"],config["message"]||"",config);
			container.hide();
		break;
		case Milan.commonutils.MODELTYPE_CONFIRM:
			container= new Milan.widget.ConfirmDialog(config["title"],config["message"]||"",config);
			//container.hide();
		break;
		case Milan.commonutils.MODELTYPE_DELAYNOTIFY:
			var duration = config["duration"]?config["duration"]:0;
			if(duration>0)
				new Milan.widget.MessageBox({content:config["message"]}).show().setCloseTimer(duration);
			else
				new Milan.widget.MessageBox({content:config["message"]}).show().setCloseTimer();
		break;
		default:
			container= new Milan.widget.Window(config["title"],config["message"]||"",config);
			container.hide();
		break;
	}
	
	if (config["url"])
		Milan.ajaxutility.updateContentUseAjax("post", config["url"], container,config);
		
	return container;
}

/**
 * 关闭打开的弹窗，如果存在的话
 * win 窗体对象
 
 */
Milan.commonutils.closeModelPop = function(win)
{
	if(win && win.closeDialog)
		win.closeDialog();
};


/*
以url参数打开一个window弹窗
目前只用于打印窗口
*/
Milan.commonutils.openPrintWindow = function(url)
{
	var printWin ;
	if(!url)
	    printWin = window.open("","printWin","height=600,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=yes");
	else
	    printWin = window.open(url,"printWin","height=600,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=yes");

	return printWin;
}

/*
用于验证form里的可提交控件值是否
*/
Milan.commonutils.formEleValidate = function(formEle)
{
	var elements = formEle.elements;
	var ele;
	var info = "";
	for(var i=0,ilen=elements.length;i<ilen;i++)
	{
		ele = elements[i];
		if(ele.getAttribute("checkEmpty"))
		{
			if((!ele.value)||ele.value==""||ele.value.trim().length<1||ele.length<1)
			{
				info += ((info=="")?"":"<br>")+ele.getAttribute("checkDesc")+"不能为空！";
			}
		}
	}
	if (info.length < 1) 
		return true;
	else {
		var dialog = Milan.commonutils.createDelayNotifyModel('提示信息',info);
		return false;
	}
}




Milan.commonutils.changeDisplay = function(ele,swapIcon)
{
	var ele = $(ele);
	var swapIcon = $(swapIcon);
	if(ele)
	{
		if(ele.style.display&&ele.style.display=="none")
		{
			if(swapIcon)swapIcon.innerHTML = "-";
			ele.style.display = "";
		}
		else
		{
			if(swapIcon)swapIcon.innerHTML = "+";
			ele.style.display = "none";
		}
	}
	
}

/*
*	判断是否是8位的日期值
*/
Milan.commonutils.isEightBitDateStr = function (dateStr)
{
	if (dateStr.length!=8) return false;
	var year = dateStr.substring(0,4);
	var month = dateStr.substring(4,6);
	var day = dateStr.substring(6,8);
	if (!Milan.string.isNumber(year)) return false;
	if (!Milan.string.isNumber(month)) return false;
	if (!Milan.string.isNumber(day)) return false;
	if (month>12 || month<1) return false;
	if (day>31 || day<1) return false;
	return true;
}


//判断一个页面元素是否有显示
Milan.commonutils.isShow = function(ele)
{
	if(ele.tagName.toUpperCase()=="BODY") return true;
	if(ele.style.display=="none"||ele.style.visibility=="hidden")
		return false;
	else
		return Milan.commonutils.isShow(ele.parentNode);		
}

/**
 * 设置对象的透明度
 *
 * @param   {HTMLElement}   el
 * @param   {Number}        opacity
 * @public
 */
Milan.commonutils.setOpacity = function(el,opacity)
{
    var style = el.style;
    if (!Milan.navigator.isIE) 
    {
        style.opacity = (opacity == 1 ? "" : opacity/100);
    } 
    else 
    {
        style.zoom = 1; 
        if (opacity == 1) 
        {
            if (typeof style.filter == "string" && (/alpha/i).test(style.filter))
                style.filter = style.filter.replace(/\s*[\w\.]*alpha\([^\)]*\);?/gi, "");
        } 
        else 
        {
            style.filter = (style.filter || "").replace(/\s*[\w\.]*alpha\([^\)]*\)/gi, "") + " alpha(opacity=" + (opacity ) + ")";
        }
    }
}


//返回对象的透明度
Milan.commonutils.getOpacity = function(el)
{
    var f=el.filters,s=el.style;
    return f?(f.alpha?(f.alpha.opacity):100):(s.opacity?s.opacity*100:100);

}

//使对象有透明渐变的效果(此函数不推荐使用，建议使用下面animateOpacity)
//opacityValue=最终的透明度
//tTime=动画的总时间
//tInterval=渐变的频率
Milan.commonutils.animateOpacity2 = function(el,opacityValue,tTime,tInterval)
{
	var iCount = tTime / tInterval;
	var perValue = opacityValue/iCount;
	for ( var i = 0; i <= iCount; i++ )
	{
		window.setTimeout(Milan.commonutils.setOpacity,tInterval * i,el,perValue*i);
	}
}

//使对象有透明渐变的效果
//opacityValue=最终的透明度
//duration=动画的持续时间(秒)，如果为0则相当于没有动画效果
//callback=回调
Milan.commonutils.animateOpacity = function(el, opacity, duration, callback)
{
	var anim = Milan.commonutils.setOpacity;
	var getOpacity = Milan.commonutils.getOpacity;
	if (duration == 0 ) 
	{
		anim(el, opacity);
		if (callback)
		    callback();
		return;
	}
	
	var from = getOpacity(el);	//此处需要补一个getElOpacity的方法来获取el当前的Opacity值
	var delta = opacity - from;	//如果from和opacity相同，说明不需要改变当前效果了
	if (delta == 0) 
	{
		if (callback)
		    callback();
		return; // nothing to animate
	}
	
	duration *= 1000; // convert to milliseconds
	
	var begin =(new Date()).getTime(),
	end = begin + duration,
	time;
	
	var interval = setInterval
	(
		function() 
		{
			time =new Date().getTime();
			if (time >= end) 
			{
			    clearInterval(interval);
			    interval = null;
			    anim(el, opacity);
			    if (callback)
			        callback();
			} 
			else 
			{
			    anim(el, from + ease((time - begin) / duration) * delta);
			}
		}
		, 
		10
	); 
    
    	//减速器
    	function ease(state) 
	{
	    return 1 + Math.pow(state - 1, 3);
	}
}

/*
* 使el动态的移动位置，并改变大小。
* el 页面元素
* toTop 	目标顶点Y坐标
* toLeft	目标顶点X坐标
* toWidth	目标宽
* toHeight	目标高
* duration	动画过程的持续时间，单位(秒)
* callback	完成后的回调
*/
Milan.commonutils.animateMoveResize = function(el, toTop,toLeft,toWidth,toHeight,duration,callback)
{
	
	function draw(el,top,left,width,height)
	{
		el.style.width = width+"px";
		el.style.height = height+"px";
		el.style.top = top+"px";
		el.style.left = left+"px";
	}
	
	if (duration == 0 ) 
	{
		draw(el, toTop,toLeft,toWidth,toHeight);
		if (callback)
		    callback();
		return;
	}
	
	toTop = parseInt(toTop);
	toLeft = parseInt(toLeft);
	toWidth = parseInt(toWidth);
	toHeight = parseInt(toHeight);
	
	var fromTop = parseInt(el.style.top);
	var fromLeft = parseInt(el.style.left);
	var fromWidth = parseInt(el.clientWidth);
	var fromHeight = parseInt(el.clientHeight);
	
	duration *= 1000; // convert to milliseconds
	
	var begin =(new Date()).getTime();
	var end = begin + duration;
	var time;
	var delta;
	var cTop = toTop-fromTop;
	var cLeft = toLeft - fromLeft;
	var cWidth = toWidth - fromWidth;
	var cHeight = toHeight - fromHeight;
	
	var interval = setInterval
	(
		function() 
		{
			time =new Date().getTime();
			if (time >= end) 
			{
			    clearInterval(interval);
			    interval = null;
			    draw(el, toTop,toLeft,toWidth,toHeight);
			    if (callback)
			        callback();
			} 
			else 
			{
			    delta = ease((time - begin) / duration);
			    
			    draw(el, fromTop+cTop*delta,fromLeft+cLeft*delta,fromWidth+cWidth*delta,fromHeight+cHeight*delta);
			    
			    
			    //anim(el, from + ease((time - begin) / duration) * delta);
			}
		}
		, 
		10
	); 
    
    	//减速器
    	function ease(state) 
	{
	    return 1 + Math.pow(state - 1, 3);
	}
}


//获取某页面元素所属的form对象
Milan.commonutils.getFormOfElement = function(element)
{
		var form = element;
		for(; form && form.tagName.toLowerCase()!="form"; form = form.parentNode);		
		return form;
}

//阻止event向下传播
Milan.commonutils.cutEvent = function(e)
{
	var evt = e || window.event;
	if (!evt) return null;
	if (Milan.navigator.isIE)
		evt.cancelBubble = true; 
	else 
		evt.stopPropagation();
	return evt;
}

//往src左边填充fillchar,直到count=src.length
Milan.commonutils.fillLeftChar = function(src, count, fillchar)
{
	if (src.length >= count) return src;
	while(src.length < count)
		src = fillchar + src;
	return src;
}

//往src右边填充fillchar,直到count=src.length
Milan.commonutils.fillRightChar = function(src,count,fillchar)
{
	if (src.length >= count) return src;
	while(src.length < count)
		src = src + fillchar;
	return src;
}


/**
 * 给页面复选框绑定事件
 * 用于检验子复选框是否宣布选中以决定父复选框是否需要被选中
 * 用于保证子复选框的状态和父复选框保持一致(全选/全不选)
 * @param formId 复选框对象所在的表单ID
 * @param parentName 父复选框的名字
 * @param childName  子复选框的名字
 * @param parentCallback{Function} 全选回调操作
 * @param childCallback{Function}  单选回调操作
 */
Milan.commonutils.checkBoxRelation = function(formId,parentName,childName,parentCallback,childCallback)
{
 	var $parentCheckAll = jQuery("#"+formId+" [name='"+parentName+"']:checkbox");
	var $childCheckList = jQuery("#"+formId+" [name='"+childName+"']:checkbox");
	$parentCheckAll.unbind('click').click(function(event){
		Milan.commonutils.cutEvent(event);
		$childCheckList.each(function(){
			this.checked = $parentCheckAll.attr("checked");
			if(childCallback){
				childCallback(this);
			}
		});
		if(parentCallback){
			parentCallback();
		}
	})
	$childCheckList.unbind('click').click(function(){
		$parentCheckAll.attr("checked",$childCheckList.length==$childCheckList.filter(":checked").length);
		if(childCallback){
			childCallback(this);
		}
	})
}

Milan.commonutils.chkClick = function(chkObj) {
	Milan.commonutils.changeTRStyleByCheckState(chkObj);
};

/**
 * 根据复选框的状态改变复选框所在行的样式，主要用在列表页中
 * 
 * @param checkItem {Element} 复选框
 * @param checkedCls {String} 复选框选中时的样式
 * @param cancelCls {String} 复选框未选中时的样式
 */
Milan.commonutils.changeTRStyleByCheckState = function(checkItem, checkedCls, cancelCls) {
	var contaniner = CheckboxSelectUtils.getContainerForCheckbox(checkItem);
	if (checkItem.checked) {
		contaniner.className = checkedCls || "checked_cls";
	} else {
		contaniner.className = cancelCls || "cancel_cls";
	}
};

/**
 * 获取包含复选框的上层元素(不一定是父节点)
 * 
 * @param checkItem {Element} 复选框
 */
Milan.commonutils.getContainerForCheckbox = function(checkItem) {
	return checkItem.parentNode.parentNode;
};

/*
* 将srcEle中的checked状态，全部设置到以str命名的元素中
* 元素一般是checkbox
* checkObj 被选中或取消选中的子复选框对象
* pName    父复选框的id
* 例:Milan.commonutils.checkAll(ele,"operatorIds");
* 当ele是选中的状态，所有以"operatorIds"命名的checkbox都会被选中，反之亦然
*/
Milan.commonutils.checkFlag = false;
Milan.commonutils.checkAll = function(pObj,childName)
{
  var children = document.getElementsByName(childName);
  var n = children.length;
  Milan.commonutils.checkFlag = !Milan.commonutils.checkFlag;
 for (var i=0; i<n; i++)
  children[i].checked = pObj.checked;
}

/**
 * 用于检验子复选框是否宣布选中以决定父复选框是否需要被选中
 * 
 * checkObj 被选中或取消选中的子复选框对象
 * pName    父复选框的id
 */
Milan.commonutils.checkItem = function(checkObj,pName)
{
  var parentCheckBox = document.getElementById(pName);
  if (checkObj.checked)
  {
    var children = document.getElementsByName(checkObj.name);
    parentCheckBox.checked = true;
    for (var i=0,ilen=children.length; i<ilen; i++)
    {
      if (!children[i].checked){
       parentCheckBox.checked = false;
       break;}
    }
  }
  else parentCheckBox.checked = false;
}

/**
 * 激活“我的桌面”Tab页
 */
Milan.commonutils.goHomePage = function() 
{
	Milan.tabbarManager.removeAllTab();
	if (Milan.currentUserId)
		Milan.tabbarManager.buildDesktop(Milan.currentUserId);
	else
		Milan.tabbarManager.buildDesktop();
	//com.milan.portlet.MainFr.init('portletAction.do');
};

/**
 * 根据option的value返回其在select控件中的索引
 * 如果没有则返回-1
 * 
 * selectEle select控件
 * optionValue option值
 */
Milan.commonutils.getOptionIndex = function(selectEle,optionValue)
{
	if(!selectEle) return -1;
	for(var i=0,ilen=selectEle.length;i<ilen;i++)
	{
		if(selectEle[i].value == optionValue)
			return i;
	}
	return -1;
}

/**
 * 根据tValue的值返回其在tArr数组中的索引
 * 如果没有则返回-1
 * 
 * tArr 数组对象
 * tValue 值
 */
Milan.commonutils.getArrayIndex = function(tArr,tValue)
{
	for (var i=0,ilen=tArr.length;i<ilen;i++)
	{
		if (tArr[i]==tValue) return i;
	}
	return -1;
}

//ip地址补全,如传入0.0.0.0,返回000.000.000.000
Milan.commonutils.IP2Full=function(ip){
	  if(!Milan.string.isIPAddr(ip))return "";
	  var ips=ip.split("\.");
	  if(ips.length!=4)return "";
	  var a=new Array(7),b=0;
	  for(var i=0;i<4;i++){
		   b=parseInt(ips[i]);
		   if(b<10)b="00"+b;else if(b<100)b="0"+b;
		   a.push(b);a.push(".");
	  }
	  a.pop();
	  return a.join("");
}

/**
 * 将焦点置于某个HTML元素上（该元素必须是HTML规定的可以聚焦的元素）
 *
 * @param elementId 需要聚焦的元素
 */
Milan.commonutils.focusElement = function(element) {
	var el;
	if(typeof element == "string")
		el = document.getElementById(element);
	else
		el = element;	
	
	if(el && el.focus)
		el.focus();
} 

/**
 * 将sourceObj对象的属性完全复制到targetObj中，source中没有的部份可以使用defaultObj的
 * 一般用于对各函数config的处理,如
 * function object(config)
 * { _config = apply(config) }
 * 
 * targetObj
 * config
 * defaultObj
 */
Milan.commonutils.apply = function(targetObj, sourceObj, defaultObj) {
	if(defaultObj)
	{
        Milan.apply(targetObj, defaultObj);
    }
    
    if(targetObj && sourceObj && typeof sourceObj == 'object'){
        for(var property in sourceObj){
            targetObj[property] = sourceObj[property];
        }
    }
    
    return targetObj;
};



if(!Array.prototype.removeItem) {
	
	/**
	 * 根据元素值删除数组中某个元素
	 * 
	 * @param 元素
	 */
	Array.prototype.removeItem = function(item) {
		for(var i = 0,ilen=this.length; i < ilen; i++) {
			if(this[i] == item) {
				this.splice(i, 1);
				break;
			}
		}
	};
}

if(!Array.prototype.itemAt) {
	
	/**
	 * 根据索引取得某个元素
	 * 
	 * @param index 元素索引 (based on zero)
	 */
	Array.prototype.itemAt = function(index) {
		return this[index];
	};
}

if(!Array.prototype.addEl) {
	
	/**
	 * 在指定位置添加一个元素
	 * 
	 * @param element
	 * @param index based on zero
	 */
	Array.prototype.addEl = function(element, index) {
		for(var i = this.length; i > index; i--) 
			this[i] = this[i - 1];

		this[index] = element;
	};
}

Milan.commonutils.toggleFadeDiv=function(ev,id,alignType)
{
	var e = ev || window.event;
	var el = e.target||e.srcElement;
	
	jQuery(el).prev("input").attr("disabled",true);
	jQuery(el).prev("input").prev("input").attr("disabled",true);
	var p = Milan.tabbarManager.getPointInActiveTab(el);
	var elWidth = jQuery(el).prop("clientWidth") || 0, elHeight = jQuery(el).prop("clientHeight") || 0;		
	var objId = "#"+id;	
	
	jQuery(objId).show();
	var objWidth = jQuery(objId).prop("clientWidth")||0,objHeight = jQuery(objId).prop("clientHeight")||0;
	jQuery(objId).hide();
	if (!alignType) alignType="right";
	if (alignType=="right")		//如果是与target的右对齐
	{
		if (Milan.navigator.isIE && parseInt(Milan.navigator.version.substring(0,1))<8)		//不是IE8的话，定位略有不同
			jQuery(objId).css({"left":p.x+elWidth-objWidth+1,"top":p.y+elHeight+6}).show().hide().fadeIn("fast");
		else
			jQuery(objId).css({"left":p.x+elWidth-objWidth-2,"top":p.y+elHeight+3}).show().hide().fadeIn("fast");
	}
	

	jQuery(objId).find(".icon-h").css({"margin-top":"5px"}).bind("click",function(){
		jQuery(objId).fadeOut("fast");//添加addClass是为了解决ie6，ie7不能立马解析样式的问题
		jQuery(el).prev("input").attr("disabled",false).addClass(jQuery(el).prev("input")[0].className);
		jQuery(el).prev("input").prev("input").attr("disabled",false);
	});
}

//获得一个form的高度，并去除掉exceptObjId的高度
Milan.commonutils.getFormHeight = function(formId,exceptObjId)
{
	var form = formId;
	if (typeof(form)!="object")
		form = jQuery("#"+formId);
				
	var exceptHeight=0;
	if (exceptObjId)
		exceptHeight = form.find("#"+exceptObjId).prop("offsetHeight");
	var height =0;
	if (Milan.navigator.isIE && parseInt(Milan.navigator.version.substring(0,1))==8)		//如果是IE8
		height =  form.prop("offsetHeight");
	else
	{
		form.children().each(
			function()
			{
				if (Milan.navigator.isIE && parseInt(Milan.navigator.version.substring(0,1))==7){
					jQuery(this).children().each(function(){height +=this.offsetHeight;});
				}else{
					height +=this.offsetHeight;
				}
			}
		)
	}
	return height-exceptHeight;
}

Milan.commonutils.checkAllInForm = function(e,checkName)
{
	var obj = e.target?e.target:e.srcElement;
	Milan.commonutils.cutEvent(e);
	var checkBoxs = jQuery(obj.form).find(":checkbox")
	if (checkName)
		checkBoxs = jQuery(obj.form).find(":checkbox[name='"+checkName+"']");
	
	checkBoxs.each(function(i,ele)
	{
		if((!obj.checked&&ele.checked)||(obj.checked&&!ele.checked)){
			if(ele.click){
				ele.click();
			}else{
				ele.checked=obj.checked;
			}
		}
	});
}

/**
 * 根据key获取内容
 * @author : zhangml
 */
Milan.commonutils.getCookie = function(key) {
	var arg = key + '=';
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			var endstr = document.cookie.indexOf(';', j);
			if (endstr == -1)
				endstr = document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
		}
		i = document.cookie.indexOf(' ', i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

/**
 * 设置cookie
 * @author : zhangml
 */
Milan.commonutils.setCookie = function(key, cValue, days) 
{
	var c = key + "=" + escape(cValue);
	if (days && typeof (days) == 'number') 
	{
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		c += "; expires=" + date.toGMTString();
	}
	document.cookie = c;
};